package com.cryptoneedle.center.doris.controller;

import com.bubbles.engine.common.core.result.Result;
import com.cryptoneedle.center.common.key.TableKey;
import com.cryptoneedle.center.doris.service.DorisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>description: Doris 控制器 </p>
 *
 * @author CryptoNeedle
 * @date 2025-09-25
 */
@Tag(name = "Doris", description = "Doris")
@RestController
@RequestMapping("/doris")
public class DorisCenterController {

    @Resource
    private DorisService dorisService;

    @Operation(summary = "同步Doris信息")
    @PostMapping("/sync/all")
    public Result<?> syncAll() {
        // todo 异常
        return dorisService.trySync() ? Result.success() : Result.failure("跳过");
    }

    @Operation(summary = "同步Doris表的列信息")
    @PostMapping("/sync/column")
    public Result<?> syncColumn(@RequestBody TableKey tableKey) {
        dorisService.syncColumn(tableKey.getCatalogName(), tableKey.getDatabaseName(), tableKey.getTableName());
        return Result.success();
    }
}